// pages/logs/details/details.js
const app = getApp();
const config = require("../../../utils/config.js");
const request = require('../../../utils/request.js');


Page({

  /**
   * 页面的初始数据
   */
  data: {
    swiperItem:[],
    id:[],
    commodityDetails:[],
    zhuanbeiAn:'',
    isclick: true,
    goumai:'',
    testColor: 'black',
    brandColor: 'black',
    testBack:'',
    brandBack:'',
    choiceColor:'black',
    choiceBack:''
  },
  toLease:function(){
    wx.navigateTo({
      url: '../../my/lease/lease',
    })
  },
  toBuyorder: function () {
    // console.log(this.data.commodityDetails.productList[0]);
    let data = {
      "goodsId": this.data.commodityDetails.productList[0].goods_id,
      "number": 1,
      "productId": this.data.commodityDetails.productList[0].id
    };
    request.request(config.addToCart, "post", data, () => {
      wx.navigateTo({
        url: '../../my/buyorder/buyorder',
      })
    });
  },
  maimai:function(){
    this.pop = wx.createAnimation({
      duration: 100,
      timingFunction: "linear",
      delay: 0,
    })
    this.pop.translateY(0).step();
    this.setData({
      goumai: this.pop.export(),
    })
  },
  maimai2: function () {
    this.pop = wx.createAnimation({
      duration: 100,
      timingFunction: "linear",
      delay: 0,
    })
    this.pop.translateY(0).step();
    this.setData({
      goumai2: this.pop.export(),
    })
  },
  fanhui:function(){
    this.pop = wx.createAnimation({
      duration: 100,
      timingFunction: "linear",
      delay: 0,
    })
    this.pop.translateY('100%').step();
    this.setData({
      goumai: this.pop.export()
    })
  },
  fanhui2: function () {
    this.pop = wx.createAnimation({
      duration: 100,
      timingFunction: "linear",
      delay: 0,
    })
    this.pop.translateY('100%').step();
    this.setData({
      goumai2: this.pop.export()
    })
  },
  testBind: function () {
    if (this.data.testColor == "black") {
      this.setData({
        testColor: '#fff',
        brandColor: 'black',
        testBack:'red',
        brandBack:''
      })
    }
  },
  crowdBind: function () {
    if (this.data.brandColor == "black") {
      this.setData({
        brandColor: '#fff',
        testColor: 'black',
        brandBack: 'red',
        testBack:''
      })
    }
  },
  choiceBind: function () {
    if (this.data.choiceColor == "black") {
      this.setData({
        choiceColor: '#fff',
        choiceBack: 'red',
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      id:options.id
    })
    console.log(this.data.id)
  },
  getData: function () {
    var that = this;
    request.request(config.commodityDetails, 'GET', {id:this.data.id}, function (res) {
      console.log(res.data.data);
      that.setData({
        commodityDetails:res.data.data
      })
    })
  },
  //点击改变爱心样式
  zhuanbeiBind: function (e) {
    console.log(123)
    this.testP = wx.createAnimation({
      duration: 100,
      timingFunction: "linear",
      delay: 0,
    })
    this.testP.scale(1).step();
    this.setData({
      zhuanbeiAn: this.testP.export()
    })
    if (this.data.isclick == true) {
      this.setData({
        isclick: false
      })
    } else {
      this.setData({
        isclick: true
      })
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getData();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})